function p(){
    // 0,页面初次渲染的时候，小计会是每个商品的单价*数量
    let li = document.querySelectorAll('#fruit li');
    //总价
    let all= document.querySelector('#all').children[0];
    let allnum = 0;
    for(let i = 0; i < li.length; i++){
        //console.log(li[i]);

        //console.log(price);单价
        let price = li[i].children[3].children[0].innerHTML;
        //console.log(num);数量
        let num = li[i].children[4].children[0].value;
        //console.log(price);小计
        let total = li[i].children[5].children[0].innerHTML = price * num;
        console.log(total);
        //总价格
        allnum += total;
        all.innerHTML = allnum;
    }
    console.log(allnum);
    // 1,页面初次更新的时候，小计的总和赋值给总价

    all.innerHTML = allnum.toFixed(2);
}
p();

// 2,只要数量的input内容发生改变，小计和总价就会更新
let num_all = document.querySelectorAll('#fruit li .num');
console.log(num_all);
for(let j = 0;j < num_all.length; j++){
    num_all[j].addEventListener('change',p);
}
// 3,删除操作之后，再根据小计计算总价

let del = document.querySelectorAll('#fruit li .del');
for(let z = 0; z < del.length; z++){
    del[z].addEventListener('click', function () {
        console.log(this);
        //var ul = document.querySelectorAll('#fruit');
        //var list = document.querySelectorAll('#fruit li');
        //ul.removeChlid(list);
        console.log(this.parentNode.parentNode);
        console.log(this.parentNode);
        this.parentNode.parentNode.removeChild(this.parentNode);
        p();
    })
}
